using System;

namespace Neural
{	
	#region interfaces

	/// <summary>
	/// Activation function interface
	/// </summary>
	public interface IActivation 
	{
		double Output(double value);
		double Prime(double value);
	}

	#endregion

	/// <summary>
	/// Sigmoid activation function
	/// </summary>
	public class Sigmoid: IActivation
	{
		public double Output(double value)
		{
			return 1 / (1 + Math.Exp(-value));
		}

		public double Prime(double value)
		{
			return value * (1 - value);
		}
	}

	/// <summary>
	/// Step activation function
	/// </summary>
	public class Step: IActivation
	{
		public double Output(double value)
		{
			return value > 0 ? 1 : 0;
		}

		public double Prime(double value)
		{
			return 1;
		}
	}
	
    /// <summary>
    /// Threshold activation function
    /// </summary>
	public class Threshold: IActivation 
	{
		public double Output(double value) 
		{
			return value > 0 ? 1 : -1;
		}

		public double Prime(double value) 
		{
			return 1;
		}
	}

    /// <summary>
	/// Tanh activation function
	/// </summary>
	public class Tanh: IActivation
	{
		public double Output(double value)
		{
			return Math.Tanh(value);
		}

		public double Prime(double value)
		{
			return (1 - value * value);
		}
	}

}
